package com.jerry.base.java8.lambda;

import java.util.List;
import java.util.function.Predicate;

/**
 * 类名::静态方法、类名::非静态方法 练习
 *
 * @author Jerry
 * @since 2024/7/31 16:55
 */
public class MethodRefExercise3 {

    record Student(String name, int age) {

        boolean test2() {
            return age >= 18;
        }
    }

    /**
     * 入参分别用：类名::静态方法、类名::非静态方法 来表示学生年龄大于等于18的条件
     *
     * @param predicate
     */
    static void highOrder(Predicate<Student> predicate) {
        List<Student> students = List.of(
                new Student("张无忌", 18),
                new Student("周芷若", 17),
                new Student("宋青书", 20)
        );

        for (Student stu : students) {
            if (predicate.test(stu)) {
                System.out.println(stu + "通过测试");
            }
        }
    }

    static boolean test1(Student stu) {
        return stu.age() >= 18;
    }

    public static void main(String[] args) {
        highOrder(MethodRefExercise3::test1);

        highOrder(Student::test2);

    }
}
